package com.base.utils;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @类描述：操作cookie的工具类
 * @创建人：wangdw
 * @创建时间：2018年11月6日 下午1:44:10
 * @版权：Copyright (c) 四川临港物流信息服务股份有限公司-版权所有.
 */
public class CookieUtil {
    private static final Logger logger = LoggerFactory.getLogger(CookieUtil.class);
    
    /**
     * 方法描述：从request对象中获取cookie
     * @param request
     * @param name
     * @return
     */
    public static String getCookie(HttpServletRequest request, String name) {
        Cookie[] cookies = request.getCookies();
        if (cookies == null) {
            return null;
        }
        for (Cookie cookie : cookies) {
            logger.debug(">>>>>>>>>>cookie:{},{},{}", cookie.getPath(), cookie.getName(), cookie.getValue());
            if (name.equalsIgnoreCase(cookie.getName())) {
                return cookie.getValue();
            }
        }
        return null;
    }
}
